package main

import (
	"github.com/julienschmidt/httprouter"
	log "github.com/sirupsen/logrus"
	"net/http"
	"strconv"
	"xj.com/oos-naming-service/config"
	health_controller "xj.com/oos-naming-service/controller/health"
	object_controller "xj.com/oos-naming-service/controller/object"
	"xj.com/oos-naming-service/error_handler"
	"xj.com/oos-naming-service/service/node"
)

func main() {
	log.Info("初始化数据上传接口...")
	log.Info("检查所有数据节点...")

	nodeService := node.New()
	nodeService.SilenceCheckAll()

	objectController := object_controller.New()

	router := httprouter.New()
	//健康检查及默认主页
	router.GET("/", health_controller.Health)
	router.GET("/health/", health_controller.Health)

	//对象
	router.GET("/objects/", objectController.Get)
	router.PUT("/objects/", objectController.Put)

	//全局异常处理，防止panic时，程序退出，不设置，在controller中panic时，客户端会收到不到响应
	router.PanicHandler = error_handler.HttpPanicHandler
	log.Fatal(http.ListenAndServe(config.Config.Server.Host+":"+strconv.Itoa(config.Config.Server.Port), router))
}
